<template>
  <div class="">
    <div class="log">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="用户名">
          <el-input v-model="formInline.user" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="formInline.password" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formInline: {
        user: "",
        password: "",
      },
    };
  },
  mounted() {},
  methods: {
    onSubmit() {
      this.$http("/login", "post", {
        username: this.formInline.user,
        password: this.formInline.password,
      }).then((res) => {
        console.log(res);
        this.$store.commit("setuser", {
          token: res.data.data.token,
          user: this.formInline.user,
        });
        this.$router.push({ path: "/student" });
      });
    },
  },
};
</script>

<style lang="scss">
.log {
  width: 800px;
  margin: 0 auto;
}
</style>
